﻿using Elsa.Server.Api.Endpoints.WorkflowDefinitions;
using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.Auth;
using Zhp.IService.Workflow.Example;
using Zhp.Model.Common;
using Zhp.Model.Workflow;
using Zhp.Workflow.Models;

namespace Zhp.Api.Controllers.Workflow
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Workflow)]
    [SeedMenu(MenuGroup = ApiGroupEnum.Workflow, Name = "流程示例", Order = 2, RouterName = "workflowexample", WebFilePath = "workflow/example/index", Icon = "leave")]
    public class WorkflowExampleController : ControllerBase
    {
        private readonly IWorkflowExampleService _workflowExampleService;

        public WorkflowExampleController(IWorkflowExampleService workflowExampleService)
        {
            _workflowExampleService = workflowExampleService;
        }

        [AllowOnline]
        [SeedList("流程测试列表", "流程示例", ApiGroupEnum.Workflow)]
        [HttpPost]
        public async Task<PageRet<WorkflowExampleModel>> Query(WorkflowExampleQuery query)
        {
            var list = await _workflowExampleService.Query(query);
            return new PageRet<WorkflowExampleModel>
            {
                TotalCount = query.TotalCount,
                DataList = list
            };
        }

        [AllowOnline]
        [HttpGet("{id}")]
        public async Task<List<ApproveTimeLine>> GetTimeLine(long id)
        {
            return await _workflowExampleService.GetTimeLine(id);
        }

        [AllowOnline]
        [HttpGet()]
        public async Task<List<WorkflowEnumModel>> GetApproveStatusSelect()
        {
            return await _workflowExampleService.GetApproveStatusSelect();
        }

        [AllowOnline]
        [HttpGet()]
        public async Task<List<WorkflowEnumModel>> GetWorkflowStatusSelect()
        {
            return await _workflowExampleService.GetWorkflowStatusSelect();
        }

        [AllowOnline]
        [HttpGet()]
        public async Task<List<string>> QueryFlowNameSelect()
        {
            return await _workflowExampleService.QueryFlowNameSelect();
        }

        [AllowOnline]
        [HttpPost]
        public async Task<bool> Create(WorkflowExampleEdit p)
        {
            return await _workflowExampleService.Create(p);
        }

        [AllowOnline]
        [HttpPost]
        public async Task<bool> Update(WorkflowExampleEdit p)
        {
            return await _workflowExampleService.Update(p);
        }

        [RepeatSubmit()]
        [AllowOnline]
        [HttpGet()]
        public async Task<bool> Submit(long id, string flowName)
        {
            return await _workflowExampleService.Submit(id, flowName);
        }

        [AllowOnline]
        [HttpGet("{id}")]
        public async Task<bool> Cancel(long id)
        {
            return await _workflowExampleService.Cancel(id);
        }

        [AllowOnline]
        [HttpGet("{id}")]
        public async Task<bool> Delete(long id)
        {
            return await _workflowExampleService.Delete(id);
        }

        [AllowOnline]
        [HttpPost]
        public async Task<bool> Approve(BaseApproveInfo approve)
        {
            return await _workflowExampleService.Approve(approve);
        }
    }
}
